//
//  CZMainViewController.swift
//  swift版新浪微博
//
//  Created by mac on 15/12/15.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit

class CZMainViewController: UITabBarController
{

    override func viewDidLoad()
    {
        super.viewDidLoad()
        let mainTabBar = CZMainTabBar()
        setValue(mainTabBar, forKey: "tabBar")
        
        let homevc = CZHomeController()
        self.addchildVC(homevc, title: "首页", imgName: "tabbar_home")
        
        let messageVC = CZMessageController()
        self.addchildVC(messageVC, title: "消息", imgName: "tabbar_message_center")
        
        let discoverVC = CZDiscoveryController()
        self.addchildVC(discoverVC, title: "发现", imgName: "tabbar_discover")
        
        let profileVC = CZProfileController()
        self.addchildVC(profileVC, title: "我", imgName: "tabbar_profile")
        // Do any additional setup after loading the view.
    }
    
    private func addchildVC(controller:UIViewController,title:String,imgName:String)
    {
        //添加tabbar的子控制器
        self.addChildViewController(UINavigationController(rootViewController: controller))
        controller.title = title
        controller.tabBarItem.image = UIImage(named: imgName)
        //拼接高亮图片的名字
        let highLightedName = imgName + "_highlighted"
        //设置tabbaritem选中时的高亮图片
        controller.tabBarItem.selectedImage = UIImage(named: highLightedName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
    controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        
    }
    
}
